package com.photographysharing.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.photographysharing.dto.PhotoDTO;
import com.photographysharing.dto.UserDTO;
import com.photographysharing.entity.Categories;
import com.photographysharing.entity.Users;
import com.photographysharing.request.SelectByPaging;
import com.photographysharing.response.DatasResponse;
import com.photographysharing.service.UsersService;
import com.photographysharing.mapper.UsersMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author Z
* @description 针对表【users】的数据库操作Service实现
* @createDate 2024-05-14 21:15:12
*/
@Service
public class UsersServiceImpl extends ServiceImpl<UsersMapper, Users>
    implements UsersService{

//    @Autowired
    private UsersMapper usersMapper;

    public UsersServiceImpl(UsersMapper usersMapper) {
        this.usersMapper = usersMapper;
    }

    @Override
    public boolean checkEmail(String email) {
        QueryWrapper<Users> QR=new QueryWrapper();
        Users  users = usersMapper.selectOne(QR.eq("email",email));
        if(users !=null){
            return true;
        }
        return false;
    }

    @Override
    public DatasResponse<UserDTO> selectByPage(SelectByPaging pag) {
        int index = pag.getIndex();
        int size = pag.getSize();
        String name = pag.getSearchName();
        String email = pag.getSearchValue1();
        List<UserDTO> datas = usersMapper.selectByPage((index-1)*size,size,name,email);
        int count = usersMapper.selectCount(name,email);
        return new DatasResponse<UserDTO>(count,datas);
    }
}




